package com.uppfind.framework.web.controller.user;

import com.uppfind.framework.commons.constants.ConstCommonString;
import com.uppfind.framework.core.controller.GenericController;
import com.uppfind.framework.core.controller.message.ResponseMessage;
import com.uppfind.framework.core.dao.api.common.params.QueryParam;
import com.uppfind.framework.core.service.GenericService;
import com.uppfind.framework.web.bean.user.User;
import com.uppfind.framework.web.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.uppfind.framework.web.bean.user.User.Property.*;

/**
 * Created by xuliugen on 2017/6/29.
 */
@RestController
@RequestMapping(value = "/user", produces = {ConstCommonString.APP_JSON_UTF_8})
public class UserController extends GenericController<User, String> {

    //默认服务类
    @Resource
    private UserService userService;

    @Override
    protected GenericService<User, String> getService() {
        return this.userService;
    }

    @Override
    public ResponseMessage list(QueryParam param) {
        param.excludes(password);
        return super.list(param)
                .exclude(User.class, password, modules, userRoles)
                .onlyData();
    }

    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public ResponseMessage select(QueryParam param) {
        param.excludes(password);
        return ResponseMessage.ok(userService.select(param));
    }
}
